/*
 * Copyright (C) 2008 GeoScheduler Team, as stated on <http://www.geoscheduler.org/authors>.
 * 
 * This file is part of GeoScheduler.
 * 
 * GeoScheduler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GeoScheduler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with GeoScheduler. If not, see <http://www.gnu.org/licenses/>.
 */
package org.geoscheduler.android.rest;

import org.geoscheduler.android.exceptions.GSContextNotInitializedException;
import org.geoscheduler.android.exceptions.GSRestFailedException;
import org.geoscheduler.android.exceptions.GSRestReturnedErrorException;
import org.json.JSONException;

/**
 * Rest client able to obtain REST API version of remote server.
 *
 * @author srakyi
 */
public class ServerAPIVersionChecker extends AbstractRestClient {
	
	public static final String RES_PATH_APIVERSION = "apiversion";
	
	public ServerAPIVersionChecker() {
		super();
	}
	
	public String getVersion() throws GSContextNotInitializedException, GSRestReturnedErrorException, GSRestFailedException {
		try {
			return restGetCall(ServerAPIVersionChecker.RES_PATH_APIVERSION).getString("version");
		} catch (JSONException e) {
			throw new GSRestFailedException("Unable to extract version from response.");
		}
	}
	
	public String getVersion(String baseURL) throws GSContextNotInitializedException, GSRestReturnedErrorException, GSRestFailedException {
		try {
			return restGetCall(baseURL, ServerAPIVersionChecker.RES_PATH_APIVERSION).getString("version");
		} catch (JSONException e) {
			throw new GSRestFailedException("Unable to extract version from response.");
		}
	}
}
